package cn.edu.nuc.crm.service.impl;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.crm.dao.CarPlanMapper;
import cn.edu.nuc.crm.dto.CarPlanShow;
import cn.edu.nuc.crm.entity.CarPlan;
import cn.edu.nuc.crm.service.interfaces.CarPlanService;
@Service
public class CarPlanServiceImpl implements CarPlanService {
	@Autowired
	private CarPlanMapper carPlanMapper;

	@Override
	public List<CarPlanShow> find(String carName) {
		// TODO Auto-generated method stub
		List<CarPlanShow> list = new ArrayList<>();
		List<CarPlan> list2 = carPlanMapper.find(carName);
		
		DecimalFormat   df   =new  DecimalFormat("#.00"); 
		
		for(int i= 0;i<3; i++){
			CarPlanShow cps = new CarPlanShow();
			CarPlan cp = new CarPlan();
			cp = list2.get(0);
			if(i == 0){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("12期/12个月");
				Double dbjp =  Double.parseDouble(cp.getBjPrice());
				cps.setTerminally(String.valueOf(df.format((0.5*dbjp+0.5*dbjp*0.04/0.96)*1/12)));
				cps.setTotal(String.valueOf(df.format(0.5*dbjp+0.5*dbjp*0.04/0.96)));
			}
			if(i == 1){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("24期/24个月");
				Double dbjp =  Double.parseDouble(cp.getBjPrice());
				cps.setTerminally(String.valueOf(df.format((0.5*dbjp+0.5*dbjp*0.07/0.93)*1/24)));
				cps.setTotal(String.valueOf(df.format(0.5*dbjp+0.5*dbjp*0.07/0.93)));
			}
			if(i == 2){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("1期/3个月");
				Double dbjp =  Double.parseDouble(cp.getBjPrice());
				cps.setTerminally(String.valueOf(df.format(0.5*dbjp+0.5*dbjp*0.05/0.95)));
				cps.setTotal(String.valueOf(df.format(0.5*dbjp+0.5*dbjp*0.05/0.95)));
			}
			
			
			
			list.add(cps);
			
			
			
		}
		
		return list;
	}

	@Override
	public List<CarPlanShow> find1(String dkje,String carName) {
		List<CarPlanShow> list = new ArrayList<>();
		List<CarPlan> list2 = carPlanMapper.find(carName);
		
		Double dkje1 =  Double.parseDouble(dkje);
		
		DecimalFormat   df   =new  DecimalFormat("#.00"); 
		
		for(int i= 0;i<3; i++){
			CarPlanShow cps = new CarPlanShow();
			CarPlan cp = new CarPlan();
			cp = list2.get(0);
			if(i == 0){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("12期/12个月");

				cps.setTerminally(String.valueOf(df.format((dkje1+dkje1*0.04/0.96)*1/12)));
				cps.setTotal(String.valueOf(df.format(dkje1+dkje1*0.04/0.96)));
			}
			if(i == 1){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("24期/24个月");
				Double dbjp =  Double.parseDouble(cp.getBjPrice());
				cps.setTerminally(String.valueOf(df.format((dkje1+dkje1*0.07/0.93)*1/24)));
				cps.setTotal(String.valueOf(df.format(dkje1+dkje1*0.07/0.93)));
			}
			if(i == 2){
				cps.setId(cp.getId());
				cps.setCarName(cp.getCarName());
				cps.setBjPrice(cp.getBjPrice());
				cps.setRegplan("1期/3个月");
				Double dbjp =  Double.parseDouble(cp.getBjPrice());
				cps.setTerminally(String.valueOf(df.format(dkje1+dkje1*0.05/0.95)));
				cps.setTotal(String.valueOf(df.format(dkje1+dkje1*0.05/0.95)));
			}
			
			
			
			list.add(cps);
			
			
			
		}
		
		return list;
	}

	@Override
	public String findbj(String carName) {
		List<CarPlan> list= carPlanMapper.find(carName);
		String bj = new String(); 
		CarPlan cp = (CarPlan)list.get(0);
		bj = cp.getBjPrice();
		return bj;
	}
	
	
	
}
